//
//	File: OyDirect3D9_enum.h
//

#ifndef OYDIRECT3D9_ENUM_H
#define OYDIRECT3D9_ENUM_H

#include <windows.h>
#include <d3d9.h>

// AdapterFormat-BackbufferFormat-WindowMode
// (windowed or fullscreen) combination that is valid
struct OyCOMBOINFO_D3DDEVICE
{
	UINT       nAdapter;             // belongs to
	D3DDEVTYPE d3dDevType;           // HAL, SW, REF
	bool       bWindowed;            // windowed mode

	D3DFORMAT  fmtAdapter;           // pixelbuffer
	D3DFORMAT  fmtBackBuffer;        // backbuffer
	D3DFORMAT  fmtDepthStencil;      // z/stencil format

	DWORD      dwBehavior;           // vertex processing
	DWORD	   dwVertexShaderVer;	 // vertex shader version
	DWORD	   dwPixelShaderVer;	 // pixel shader version
	DWORD	   dwVertexShaderConst;	 // vertex shader registers num
	D3DMULTISAMPLE_TYPE msType;      // multisample type
};

struct OyDEVICEINFO_D3DDEVICE
{
	UINT					nAdapter;        // belongs to
	D3DDEVTYPE				d3dDevType;      // HAL, SW, REF
	D3DCAPS9				d3dCaps;         // capabilites
	OyCOMBOINFO_D3DDEVICE	d3dCombo[80];    // combo
	UINT					nNumCombo;       // number of combos
};

struct OyADAPTERINFO_D3DDEVICE
{
	D3DADAPTER_IDENTIFIER9	d3dAdapterIdentifier;
	UINT					nAdapter;         // which one
	D3DDISPLAYMODE			d3ddspmd[150];    // display modes
	UINT					nNumModes;        // number of modes
	OyDEVICEINFO_D3DDEVICE  d3dDevs[3];       // list of devices
	UINT					nNumDevs;         // number of devices
};

class OyDirect3D9Enum 
{
public:
	OyDirect3D9Enum(int nMinDepth, int nMinStencil)
	{
		m_nMinDepth = nMinDepth;  
		m_nMinStencil = nMinStencil; 
	}
	~OyDirect3D9Enum(void) { /* nothing to do */ }

	// enumerate all the stuff
	HRESULT Enum(void);

	// get d3d device settings
	BOOL LoadD3DSetting(OyDEVICEINFO_D3DDEVICE *pD, D3DDISPLAYMODE *dspmd,
                         D3DFORMAT *fmtA, D3DFORMAT *fmtB, bool *bWindowed,
						 D3DMULTISAMPLE_TYPE *dwMultiSample);

	LPDIRECT3D9				m_pD3D;
	OyADAPTERINFO_D3DDEVICE m_xAdapterInfo[10];
	DWORD					m_dwNumAdapters;
      

private:
	D3DDISPLAYMODE m_dspmd;    // current desktop display mode
	D3DFORMAT m_fmtAdapter[5]; // list of possible adapter formats
	UINT      m_nNumFmt;       // adapter formats possible
	UINT      m_nMinWidth;     // minimum screen with
	UINT      m_nMinHeight;    // minimum screen height
	UINT      m_nMinBits;      // minimum backbuffer bits
	UINT      m_nMinDepth;     // minimum depth bits
	UINT      m_nMinStencil;   // minimum stencil bits

	HRESULT EnumAdapters(void);
	HRESULT EnumDevices(OyADAPTERINFO_D3DDEVICE &xAdapter);
	HRESULT EnumCombos(OyDEVICEINFO_D3DDEVICE &xDev);

	UINT    GetBits(D3DFORMAT fmt);
	HRESULT ConfirmDevice(D3DCAPS9 *pCaps, DWORD dwBehavior, D3DFORMAT fmtBackbuffer);
	bool    ConfirmDepthFmt(OyCOMBOINFO_D3DDEVICE *pCombo);
};


#endif